
/**
 * AppleIIGo
 * Memory class
 * (C) 2008 by Marc S. Ressl(mressl@umich.edu)
 * Released under the GPL
 */

#include "Motherboard.h"

#ifndef MEMORY_H
#define MEMORY_H

typedef enum {
	MEMORYTYPE_II,
	MEMORYTYPE_IIE,
	MEMORYTYPE_IIC,
	MEMORYTYPE_IIGS,
};

class Memory : public Device {
public:
	Memory(class Motherboard * motherboard,
		   UINT32 mainMemoryType, UINT32 mainMemoryByteNum,
		   char * romImage, UINT32 romByteNum, UINT32 romBank1Index);
	~Memory();
	
	void onMemoryRequested();
	void onMemoryAllocated();
	void onResetAsserted(bool isRestart);
	
	UINT32 requestMemory(UINT32 byteNum);
	bool allocateMemory();
	UINT8 * getMemory(UINT32 offset);
	
	UINT32 getMainMemoryOffset(UINT32 offset);
	UINT8 * getShadowMemory();
	
	bool loadRomImage(UINT32 offset, UINT32 byteNum, char * romImage);
	
private:
	class MMU * mmu;
	
	UINT32 memoryPoolByteNum;
	UINT8 * memoryPool;
	
	UINT32 mainMemoryType;
	UINT32 mainMemoryByteNum;
	UINT32 mainMemoryOffset;
	
	UINT32 shadowMemoryOffset;
	
	char * romImage;
	UINT32 romByteNum;
	UINT32 romBank1Index;
	UINT32 romOffset;
	
	void loadDefaultBootRomImage();
};

#endif
